﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DADOS.config;

namespace PROAD.admin.Forms
{
    public partial class formConfigAgenda : System.Web.UI.Page
    {
        DADOS.config.metConfig metConf = new metConfig();

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                CarregarForm();
            }
        }

        protected void CarregarForm()
        {
            var objConfig = metConf.RetonarConfigAgenda();
            txtAD1.Text = objConfig.NR_DIAS_AD1.ToString();
            txtAD2.Text = objConfig.NR_DIAS_AD2.ToString();
            txtAD3.Text = objConfig.NR_DIAS_AD3.ToString();
        }

        protected void btnGravarConfig_Click(object sender, EventArgs e)
        {
            var objConfig = metConf.RetonarConfigAgenda();
            objConfig.NR_DIAS_AD1 = txtAD1.Text != "" ? Convert.ToInt32(txtAD1.Text) : 1;
            objConfig.NR_DIAS_AD2 = txtAD2.Text != "" ? Convert.ToInt32(txtAD2.Text) : 1;
            objConfig.NR_DIAS_AD3 = txtAD3.Text != "" ? Convert.ToInt32(txtAD3.Text) : 1;
            metConf.AlterarConfigAgenda(objConfig);
            txtTituloMsn.Text = "ALERTA";
            txtTextoMsn.Text = "Configuração de agenda gravada com sucesso!";
            ModalPopupMsn.Show();
        }
    }
}